package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.CompensateDao;
import ysq.xyg.model.Compensate;
import ysq.xyg.model.Compensate;
import ysq.xyg.service.CompensateService;
import ysq.xyg.util.EasyPoiUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:37
 **/
@Service("compensateService")
public class CompensateServiceImpl extends BaseServiceImpl<Compensate> implements CompensateService {
    @Resource
    private CompensateDao compensateDao;

    @Autowired
    public void setBaseDao(CompensateDao compensateDao) {
        this.baseDao = compensateDao;
    }

    @Override
    public PageInfo<Compensate> pageInfo(Compensate compensate, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        Example example = new Example(Compensate.class);
        Example.Criteria criteria = example.createCriteria();
        List<Compensate> list=compensateDao.selectByExample(example);
        return new PageInfo<Compensate>(list);
    }
    @Override
    public List<Compensate> list(Compensate compensate) {
        //通用Example查询
        Example example = new Example(Compensate.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(compensate.getMonth())) {
            criteria.andEqualTo("month",compensate.getMonth());
        }
        if (StringUtil.isNotEmpty(compensate.getWangWang())) {
            criteria.andEqualTo("wangWang",compensate.getWangWang().trim());
        }
        if (StringUtil.isNotEmpty(compensate.getRemoveTag())) {
            criteria.andEqualTo("removeTag",compensate.getRemoveTag().trim());
        }
        List<Compensate> list=compensateDao.selectByExample(example);
        return list;
    }
    public PageInfo<Compensate> pageLeft(Compensate compensate, int pageSize, int pageNum){
        PageHelper.startPage(pageNum,pageSize);
        List<Compensate> list=compensateDao.listLeft(compensate);
        return new PageInfo<Compensate>(list);
    }
    /**
     *@Author: YuShengQiang
     *@Date: 2018-12-05 16:16
     *@Description:数据导出
     */
    @Override
    public void export(HttpServletResponse response, Compensate compensate) {
        String title="追加补偿登记";
        List<Compensate> list=compensateDao.listLeft(compensate);
        // 导出操作
        EasyPoiUtil.exportExcel(list, title, "追加补偿登记信息", Compensate.class, title+".xls", response);
    }
}
